package com.dmpp.mes.service.impl;


import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.AromaMapper;
import com.dmpp.mes.dao.SemiTypeMapper;
import com.dmpp.mes.parameterInfo.Aroma;
import com.dmpp.mes.parameterInfo.SemiType;
import com.dmpp.mes.service.AromaService;
import com.dmpp.mes.service.SemiTypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "SemiTypeService")

public class SemiTypeServiceImpl implements SemiTypeService {

    @Autowired
    private SemiTypeMapper mapper;


    @Override
    public ResponseData findAll(SemiType semiType) {
        ResponseData responseData = new ResponseData();
        PageInfo pageInfo = new PageInfo<>(mapper.findAll(semiType));
        responseData.setData(pageInfo);
        return responseData;
    }

    @Override
    public ResponseData findByCode(String code) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.findByCode(code));
        return responseData;
    }

    @Override
    public ResponseData insert(SemiType semiType) {
        ResponseData responseData = new ResponseData();
        SemiType semiType1= mapper.findByCode(semiType.getCode());
        if (semiType1==null){
            mapper.insert(semiType);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR2001);
        }
        return responseData;
    }

    @Override
    public ResponseData updateByCode(SemiType semiType) {
        ResponseData responseData = new ResponseData();
        mapper.updateByCode(semiType);
        return responseData;
    }

    @Override
    public ResponseData deleteByCode(String code) {
        ResponseData responseData = new ResponseData();
        mapper.deleteByCode(code);
        return responseData;
    }

    @Override
    public ResponseData delete(String code) {
        ResponseData responseData = new ResponseData();
        int number= mapper.count(code);
        if (number==0){
            mapper.delete(code);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR1016);
        }
        return responseData;
    }

}
